package ch.bfh.abch.rems.sender.tinkerforge;

import org.apache.log4j.Logger;

import ch.bfh.abch.rems.sender.MulticastSender;
import ch.bfh.abcm.rems.REMSMessageType;
import ch.bfh.abcm.rems.tinkerforge.TFNodeAverageMessage;

import com.google.gson.Gson;

public class TFMulticastSender extends MulticastSender {
    
    private static Logger logger = Logger.getLogger("play");

    public TFMulticastSender(String multicastAdress, int receiverPort) {
        super(multicastAdress, receiverPort);
    }
    
    private byte[] getByteArrayFromTFCNA(TFNodeAverageMessage nodeAverageMessage){
        logger.info("Create clusterNodeAverageObject as String with Gson");
        String cnaString = new Gson().toJson(nodeAverageMessage);
        logger.debug("SendData: "+cnaString);
        return getMulticastMessageByteArray(REMSMessageType.TF_NODE_AVERAGE, cnaString);
    }

    @Override
    public void sendTFNodeAverageMessage(TFNodeAverageMessage nodeAverageMessage) {
        sendDatagramPacket(getByteArrayFromTFCNA(nodeAverageMessage));
    }
}
